Automated refactoring to the Null Object design pattern

نویسندگان

  • Maria Anna G. Gaitani
  • Vassilis Zafeiris
  • N. A. Diamantidis
  • Emmanouel A. Giakoumakis
چکیده

Context: Null-checking conditionals are a straightforward solution against null dereferences. However, their frequent repetition is considered a sign of poor program design, since they introduce source code duplication and complexity that impacts code comprehension and maintenance. The Null Object design pattern enables the replacement of null-checking conditionals with polymorphic method invocations that are bound, at runtime, to either a real object or a Null Object. Objective: This work proposes a novel method for automated refactoring to Null Object that eliminates null-checking conditionals associated with optional class fields, i.e., fields that are not initialized in all class instantiations and, thus, their usage needs to be guarded in order to avoid null dereferences. Method: We introduce an algorithm for automated discovery of refactoring opportunities to Null Object. Moreover, we specify the source code transformation procedure and an extensive set of refactoring preconditions for safely refactoring an optional field and its associated null-checking conditionals to the Null Object design pattern. The method is implemented as an Eclipse plug-in and is evaluated on a set of open source Java projects. Results: Several refactoring candidates are discovered in the projects used ∗Corresponding author. Address: Patission 76, 104 34, Athens, Greece. Tel: +302108203183, Fax: +302108203275 Email addresses: [email protected] (Maria Anna G. Gaitani), [email protected] (Vassilis E. Zafeiris), [email protected] (N. A. Diamantidis), [email protected] (E. A. Giakoumakis) Preprint submitted to Information and Software Technology October 27, 2014 in the evaluation and their refactoring lead to improvement of the cyclomatic complexity of the affected classes. The successful execution of the projects’ test suites, on their refactored versions, provides empirical evidence on the soundness of the proposed source code transformation. Runtime performance results highlight the potential for applying our method to a wide range of project sizes. Conclusion: Our method automates the elimination of null-checking conditionals through refactoring to the Null Object design pattern. It contributes to improvement of the cyclomatic complexity of classes with optional fields. The runtime processing overhead of applying our method is limited and allows its integration to the programmer’s routine code analysis activities.

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Inferring design patterns using the ReP graph

Periodic refactoring of a large source code often becomes a necessity especially for long-lived projects. In order to increase maintainability and extensibility of such projects, design pattern based refactoring can be seen as an emerging alternative. Manual inspection of source code to find candidate spots where patterns can be introduced is time consuming. Therefore automated tools can help i...

متن کامل

SPQR: Formalized Design Pattern Detection and Software Architecture Analysis

We present formal analysis methods and results from SPQR, the System for Pattern Query and Recognition, a toolkit that detects instances of known design patterns directly from object-oriented source code in an automated and flexible manner. Based on previous work in rhocalculus (extended Abadi/Cardelli sigma-calculus) and Pattern/Object Markup Language (POML), the SPQR toolset is easily retarge...

متن کامل

Automated refactoring to the Strategy design pattern

Context: The automated identification of code fragments characterized by common design flaws (or ‘‘code smells’’) that can be handled through refactoring, fosters refactoring activities, especially in large code bases where multiple developers are engaged without a detailed view on the whole system. Automated refactoring to design patterns enables significant contributions to design quality eve...

متن کامل

A Multi-Objective Refactoring Approach to Introduce Design Patterns and Fix Anti-Patterns

Refactoring is widely recognized as a crucial technique applied when evolving object-oriented software systems. Refactoring has promised, if applied well, to improve software readability, maintainability and extendibility. In general, to improve software quality, most of existing studies focus on the correction of anti-patterns or enhancing specific quality metrics. However, this may not be suf...

متن کامل

An Automated Refactoring Approach to Design Pattern-Based Program Transformations in Java Programs

Software often needs to be modified for accommodating requirements changes through the software life cycle. To deal with several accidental requirements changes related to software maintenance, a systematic and safe approach to modifying softwares is needed. The design patterns provide a high degree of design flexibility for such accidental requirements changes. In this paper, we propose an aut...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:
  • Information & Software Technology

دوره 59  شماره 

صفحات  -

تاریخ انتشار 2015